import React, { ReactElement } from 'react';
import { View, Text, Image, Clipboard, Linking } from 'react-native';

import Button from '../../components/Button';
import NavBar from '../../components/NavBar';
import Notch, { NotchType } from '../../components/Notch';
import { isIOS } from '../../constant';
import { contactUsIcon } from '../../constant/resource';
import { toolTipOpen } from '../../util/global';
import styles from './style';

export default (): ReactElement => {
  const wechatNumber = 'zhang_yutou';

  const copyWechatNumber = (): void => {
    Clipboard.setString(wechatNumber);
    toolTipOpen({ desc: '微信号已复制' });

    if (!isIOS) return;

    Linking.canOpenURL('weixin://').then((supported): void => {
      if (supported) {
        Linking.openURL('weixin://');
      } else {
        toolTipOpen({
          desc: '请先安装微信'
        });
      }
    });
  };

  return (
    <Notch style={styles.container} type={NotchType.Top}>
      <NavBar title="联系我们" />
      <View style={styles.content}>
        <Image source={contactUsIcon} style={styles.icon} />
        <Text style={styles.title}>添加助教老师微信</Text>
        <Text style={styles.subTitle}>可领取独家资料与优惠</Text>
        <View style={styles.loadWechat}>
          <Text style={styles.wechat}>微信号：{wechatNumber}</Text>
        </View>
      </View>
      <Button
        style={styles.copy}
        text="复制微信号，去微信添加"
        textStyle={styles.copyDesc}
        onPress={copyWechatNumber}
      />
    </Notch>
  );
};
